/**
 * @param {string} s
 * @return {string[]}
 */
var letterCasePermutation = function (s) {
  let path = []
  let res = []

  function backtracking(s, i) {
    if (path.length == s.length) {
      res.push(path.join(''))
      return
    }
    for (let k = i; k < s.length; k++) {
      if (s[k] >= 'a' && s[k] <= 'z') {
        path.push(s[k])
        backtracking(s, k + 1)
        path.pop()
        // path.pop()
        path.push(s[k].toUpperCase())
        backtracking(s, k + 1)
        path.pop()
      } else if (s[k] >= 'A' && s[k] <= 'Z') {
        path.push(s[k])
        backtracking(s, k + 1)
        path.pop()
        // path.pop()
        path.push(s[k].toLowerCase())
        backtracking(s, k + 1)
        path.pop()
      } else {
        path.push(s[k])
        backtracking(s, k + 1)
        path.pop()
      }
    }
  }
  backtracking(s, 0)

  return res
}

console.log(letterCasePermutation('a1B2'));
